package com.mojo.dao;

import com.mojo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2021, 广州九尾信息科技有限公司
 * @date 2021/6/21 14:17
 */
@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int updateUser(Long id) {
        String sql = "update backstage_user set nickname= ? where id=?";
        Object[] objects = {"mojo", 1};
        int update = jdbcTemplate.update(sql, objects);
        return update;
    }

    @Override
    public int insert() {
        String sql = "insert into backstage_user(username,nickname,phone) values(?,?,?)";
        Object[] obj = {"姓名", "昵称", "18888886258"};
        return jdbcTemplate.update(sql, obj);
    }

    @Override
    public User select(Long id) {
        String sql = "select * from backstage_user where id=?";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql, id);
        for (Map<String, Object> map : maps) {
            System.out.println(map);
        }
        return null;
    }

    @Override
    public int delete(Long id) {

        return 0;
    }

    @Override
    public int batchInsert(List<User> list) {
        String sql = "insert into backstage_user(username,nickname,phone) values(?,?,?)";
        ArrayList<Object> objects = new ArrayList<>();
        jdbcTemplate.batchUpdate(sql);
        return 0;
    }
}
